package projectdemo01.operation;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User:咭咭熊
 * Date:2021 - 09 - 23
 * Time:19:47
 */

import projectdemo01.book.Book;
import projectdemo01.book.BookList;

import java.util.Scanner;

/***
 * 添加书籍操作
 */
public class AddOperation implements IOperation{

    @Override
    public void work(BookList bookList) {
        System.out.println("添加书籍！");
        //书架就是一个顺序表，每次将书籍插入到数组的最后；
        //先组装一本书
        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入图书的名字：");
        String bookname = scanner.nextLine();
        System.out.println("请输入图书的作者：");
        String author = scanner.nextLine();
        System.out.println("请输入图书的价格：");
        int price = scanner.nextInt();
        System.out.println("请输入图书的类型：");
        //上面是nextInt,下面是nextLine,则下一行就读不到输入的额数据，将下一行的nextLine改为next()
        String type = scanner.next();
        Book book = new Book(bookname,author,price,type);

        int currentSize = bookList.getUsedSize();//获取当前顺序表的长度
        bookList.setBooks(currentSize,book);//在当前位置插入书籍
        bookList.setUsedSize(currentSize + 1);//修改当前顺序表的长度
    }
}
